﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Newtonsoft.Json;

public partial class _reportContent :Basic
{
    public string strContent = "";
    public string strNewsRelated = "";
    public int ID = 0;
    public string cpbdList = "";
    public string jdtjList = "";
    public string ydphList = "";
    public string ltjhList = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        ID = OTO.ToInt(Request["ID"], 0);

        strContent = sbContent(ID).ToString();

        strNewsRelated = sbNewsRelated(ID).ToString();

        cpbdList = sbCPBDList().ToString();

        jdtjList = sbJDTJList().ToString();

        ydphList = sbYDPHList().ToString();

        ltjhList = sbLTJHList().ToString();
    }

    private StringBuilder sbContent(int ID)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            if (ID > 0)
            {
                StringBuilder sbfx = new StringBuilder();
                sbfx.AppendLine("<div class=\"tj\">");
                sbfx.AppendLine("  <div class=\"tj_l\">");
                sbfx.AppendLine("    <div id=\"ckepop\">			");
                sbfx.AppendLine("	    <a href=\"http://www.jiathis.com/share/?uid=900010\" class=\"jiathis jiathis_txt jtico jtico_jiathis\" target=\"_blank\">分享到：</a>");
                sbfx.AppendLine("	    <a class=\"jiathis_button_qzone\">QQ空间</a>");
                sbfx.AppendLine("	    <a class=\"jiathis_button_tsina\">新浪微博</a>");
                sbfx.AppendLine("            <a class=\"jiathis_button_tqq\">腾讯微博</a>");
                sbfx.AppendLine("           <a class=\"jiathis_button_tsohu\">搜狐微博</a>");
                sbfx.AppendLine("            <a class=\"jiathis_button_t163\">网易微博</a>	");
                sbfx.AppendLine("    </div>  ");
                sbfx.AppendLine("  </div>");
                sbfx.AppendLine("  <div class=\"tj_r\">");
                sbfx.AppendLine("  <iframe src=\"http://open.qzone.qq.com/like?url=http%3A%2F%2Fuser.qzone.qq.com%2F1025234786&type=button_num&width=400&height=30\" allowtransparency=\"true\" scrolling=\"no\" border=\"0\" frameborder=\"0\" style=\"width:400px;height:30px;border:none;overflow:hidden;\"></iframe>");
                sbfx.AppendLine("  </div>");
                sbfx.AppendLine("  <div class=\"clearok\"></div>");
                sbfx.AppendLine("</div>");

                string url = jsonUrl + "news/report.ashx?id=" + ID;
                string str = Pub.LoadData(url);
                NewsContentEnty obj = JsonConvert.DeserializeObject<NewsContentEnty>(str);
                if (obj != null)
                {
                    sb.AppendLine("<ul class=\"news_14ul\">");
                    sb.AppendLine("<li class=\"h1 center\">" + obj.Title + "</li>");
                    sb.AppendLine("<li class=\"gray sjian center\">" + OTO.ToDate(obj.PTime, DateTime.Now).ToString("yyyy年M月d HH:mm") + " " + obj.Source + "</li>");
                    sb.Append(sbfx.ToString());

                    if (string.IsNullOrEmpty(obj.Summary))
                        sb.AppendLine("<li><div class=\"line\"></div></li>");
                    else
                        sb.AppendFormat("<div class=\"daodu\">[<span class=\"fw\">导读</span>]{0}</div>", obj.Summary);

                    sb.AppendLine("<div class=\"text-indent\">");
                    sb.AppendLine("" + obj.Content + "");
                    sb.AppendLine("</div>");
                    sb.AppendLine("</ul>");
                    sb.AppendLine("<div class=\"clearok\"></div>");

                }
            }
        }
        catch (Exception ex)
        { }
        return sb;
    }

    private StringBuilder sbNewsRelated(int ID)
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/NewsRelated.ashx?newsid=" + ID + "&top=5";
            string str = Pub.LoadData(url);
            List<NewsListEnty> list = JsonConvert.DeserializeObject<List<NewsListEnty>>(str);

            sb.Append("<ul class=\"news_14ul news_pos\">");
            sb.Append("<li>相关阅读：</li>");
            for (int i = 0; i < list.Count; i++)
            {
                sb.AppendLine("<li> ·<a href=\"newsContent.aspx?ID=" + list[i].Id + "\" class=\"b\">" + list[i].Title + "</a><span class=\"news_l_rq\">" + OTO.ToDate(list[i].PTime, DateTime.Now).ToString("yyyy-MM-dd") + "</span></li>");
            }
            sb.Append("</ul>");
        }
        catch { }
        return sb;
    }

    private StringBuilder sbCPBDList()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/module.ashx?id=cpbb";
            string str = Pub.LoadData(url);
            List<List<NewsSBEnty>> obj = JsonConvert.DeserializeObject<List<List<NewsSBEnty>>>(str);
            foreach (var item in obj)
            {
                sb.AppendFormat("<li>");
                for (int i = 0; i < item.Count; i++)
                {
                    sb.AppendFormat("<a href=\"{1}\"><span style=\"color:{2};font-weight:{3}\">{0}</span></a> ", item[i].Text, item[i].Url, item[i].Color, item[i].FontWeight);
                }
                sb.AppendFormat("</li>");
                //sb.AppendFormat("<br />");
            }
        }
        catch { }
        return sb;

    }

    private StringBuilder sbJDTJList()
    {
        StringBuilder sbCPBD = new StringBuilder();
        try
        {
            string url = jsonUrl + "comm/module.ashx?id=jdtj";
            string str = Pub.LoadData(url);
            List<List<NewsSBEnty>> obj = JsonConvert.DeserializeObject<List<List<NewsSBEnty>>>(str);
            int i = 0;
            foreach (var item in obj)
            {
                //if (item.Count == 3)
                //{
                sbCPBD.Append("<li><a href=\"" + item[0].Url + "\" class=\"b\">" + item[0].Text + "</a>&nbsp;</li>");
                //sbCPBD.Append("<a href=\"" + item[1].Url + "\" class=\"b\">" + item[1].Text + "</a>&nbsp;");
                //sbCPBD.Append("<a href=\"" + item[2].Url + "\" class=\"b\">" + item[2].Text + "</a>&nbsp;");
                i++;
                if (i >= 6)
                    break;
                //}
            }
        }
        catch { }
        return sbCPBD;
    }

    private StringBuilder sbYDPHList()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/ydph.ashx";
            string str = Pub.LoadData(url);
            List<NewsListEnty> list = JsonConvert.DeserializeObject<List<NewsListEnty>>(str);
            int len = 7;
            if (list.Count < len)
                len = list.Count;
            sb.Append("<ul>");
            for (int i = 0; i < len; i++)
            {
                sb.AppendFormat("<li> ·<a href=\"{1}\">{0}</a> </li>", list[i].Title, GetNewsUrl("00", "0", list[i].Id));
            }
            sb.Append("</ul>");
        }
        catch { }
        return sb;
    }

    private StringBuilder sbLTJHList()
    {
        StringBuilder sb = new StringBuilder();
        try
        {
            string url = jsonUrl + "news/ltjh.ashx";
            string str = Pub.LoadData(url);
            List<NewsListEnty> list = JsonConvert.DeserializeObject<List<NewsListEnty>>(str);
            int len = 7;
            if (list.Count < len)
                len = list.Count;
            sb.Append("<ul>");
            for (int i = 0; i < len; i++)
            {
                sb.AppendFormat("<li> ·<a href=\"{1}\">{0}</a> </li>", list[i].Title, list[i].Url);
            }
            sb.Append("</ul>");
        }
        catch
        { }
        return sb;
    }
}